﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace Rio.WCF.Services.helpers
{
    public class Utils
    {
        /// <summary>
        /// Remove extention without remove root Directory 
        /// </summary>
        /// <param name="filename">File name </param>
        /// <returns></returns>
        public static string RemoveExtension(string filename)
        {
            if (string.IsNullOrEmpty(filename))
                return string.Empty;

            return filename.Substring(0, filename.Length - Path.GetExtension(filename).Length);
        }

        /// <summary>
        /// Converts the file name to file format.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        public static NetBay.Core.BusinessEntities.Constant.ImageFileFormat ConvertFileNameToFileFormat(string filename)
        {
            string ext = Path.GetExtension(filename) ;
            string extWithoutPoint = ext.Substring(ext.LastIndexOf('.') + 1);

            NetBay.Core.BusinessEntities.Constant.ImageFileFormat ImageFileFormat = NetBay.Core.BusinessEntities.Constant.ImageFileFormat.TIF;
            Enum.TryParse<NetBay.Core.BusinessEntities.Constant.ImageFileFormat>(extWithoutPoint, out ImageFileFormat);
            return ImageFileFormat;
        }
    }
}